home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / wbdialog.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  49KB  |  1,732 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        wbdialog.c
  13.  * Purpose:     workbench GUI dialog
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     19-Nov-1993 CPP; Created.
  16.  *              4-Aug-94 CPP (1.04); Filenames may contain spaces
  17.  *              5-Aug-94 CPP (1.05); Make append apply to name shown
  18.  *              5-Aug-94 CPP (1.10); Minor interface improvements
  19.  *              31-Aug-94 CPP (1.13); Fix display of pre-set LogX and LogY
  20.  *              14-Dec-94 CPP (1.17); Fix display of gadgets w. >4 colors
  21.  *               5-Jan-95 CPP (1.18); Use system default font if possible
  22.  *              20-Jan-1994 CPP (1.23); Use icon tooltypes
  23.  *              26-Jan-95 CPP (1.26); Allow largest possible font size
  24.  *              27-Jan-95 CPP (1.27); Report window open failure
  25.  *              28-Jan-95 CPP (1.28); Nag requester
  26.  *              28-Jan-95 CPP (1.29); Labeled radio buttons
  27.  *              28-Jan-95 CPP (1.30); Tall buttons for emphasis
  28.  *               6-Feb-95 CPP (1.31); Progress Requester
  29.  *
  30.  * Comments:    Workbench GUI.  Amiga Dependent!
  31.  *              We must exit from here on all fatal errors!
  32.  *              (Note: might have been started from CLI.  In that case,
  33.  *               don't expect to find any workbench message or icons.
  34.  *               Read and write files and options might already have been
  35.  *               selected through CLI arguments or commands.)
  36.  */
  37.  
  38. #ifdef AMIGA  /* This module is AMIGA dependent */
  39.  
  40. #include <stdio.h>     /* sprintf() */
  41. #include <string.h>
  42.  
  43. /* #define ONLY_OK_TALL */
  44.  
  45. /*
  46.  * Amiga includes
  47.  */
  48. #include <exec/types.h>
  49. #include <workbench/workbench.h>
  50. #include <intuition/intuition.h>
  51. #include <clib/intuition_protos.h>
  52. #include <clib/exec_protos.h>
  53. #include <dos.h> /* chkabort() */
  54.  
  55. /*
  56.  * GFFT includes
  57.  */
  58. #include "gfft.h"
  59. #include "settings.h"  /* for testing */
  60. #include "wbench.h"
  61. #include "format.h"
  62.  
  63. /*
  64.  * special global variables defined here
  65.  */
  66. struct Window *dialog_window_p = NULL;
  67. struct Gadget *message_gadgetp;
  68.  
  69. /*
  70.  * Semi-global variables
  71.  */
  72. extern LONG num_files;
  73. extern LONG file_index;
  74. extern double LoopTimeElapsed;
  75. extern int Tooltype_Errors;
  76.  
  77. /*
  78.  * Strings from messages[.c|.h]
  79.  */
  80. extern const char NameAuthor[];
  81. extern const char VersionData[];
  82. extern const char Copyright[];
  83. extern char *Please_Select_Read_File_S;
  84. extern char *Set_Parameters_Then_Ok_S;
  85. extern char *Attempting_to_Perform_FFT_S;
  86. extern char *Set_Sampling_Rate_S;
  87. extern char *Verify_Sampling_Rate_S;
  88. extern char *Dialog_Window_Title;
  89.  
  90. /*
  91.  * From wbtools
  92.  */
  93. extern BOOLEAN Old_Intuition;
  94. extern short Screen_Font_Height;
  95. extern short Font_Height;
  96. extern short Font_Width;
  97.  
  98. /*
  99.  * From Amiga Hardware Reference Manual
  100.  */
  101. #define RAW_HELP_KEY 0x5f
  102.  
  103. /*
  104.  * Window definitions
  105.  */
  106. #define FONT_SIZE 8
  107.  
  108. #define MAX_TEXT_COLS 75  /* This turns out to be the max we can get with screen width = 640 */
  109.  
  110. #define BUTTON_ROWS 9       /* This allows a small console window beneath window when height = 200 */
  111.  
  112. #define SELECT_READ_FILE 1
  113. #define SELECT_PARAMETERS 2
  114. #define PERFORMING_FFT 3
  115. #define REMEMBER_MESSAGE 4
  116. #define SET_RATE 5
  117. #define VERIFY_RATE 6
  118.  
  119. /*
  120.  * Static variables for this file
  121.  */
  122. static struct Gadget *octave_2_gadgetp, *octave_3_gadgetp;
  123. static struct Gadget *octave_4_gadgetp, *octave_5_gadgetp;
  124. static struct Gadget *octave_6_gadgetp, *octave_7_gadgetp;
  125. static struct Gadget *octave_low_gadgetp, *octave_hi_gadgetp;
  126. static struct Gadget *ok_gadgetp, *CLI_gadgetp, *next_gadgetp;
  127. static struct Gadget *copyright_gadgetp, *select_read_gadgetp;
  128. static struct Gadget *read_file_gadgetp, *con_read_gadgetp;
  129. static struct Gadget *one_shot_gadgetp, *repeat_only_gadgetp;
  130. static struct Gadget *channel_gadgetp, *rate_gadgetp, *bins_gadgetp;
  131. static struct Gadget *bins_max_gadgetp, *overlap_gadgetp, *pad_gadgetp;
  132. static struct Gadget *interleave_gadgetp, *no_interleave_gadgetp;
  133. static struct Gadget *rectangle_gadgetp, *welch_gadgetp, *parzen_gadgetp;
  134. static struct Gadget *b_h_74db_gadgetp, *triangle_gadgetp;
  135. static struct Gadget *b_h_92db_gadgetp;
  136. static struct Gadget *hamming_gadgetp, *combine_plots_gadgetp;
  137. static struct Gadget *hann_gadgetp, *pink_gadgetp, *def_write_gadgetp;
  138. static struct Gadget *write_file_gadgetp, *cancel_write_gadgetp;
  139. static struct Gadget *low_f_gadgetp, *high_f_gadgetp, *time_segs_gadgetp;
  140. static struct Gadget *plot_gadgetp, *log_x_gadgetp, *log_y_gadgetp;
  141. static struct Gadget *amplitude_gadgetp, *power_gadgetp, *db_gadgetp;
  142. static struct Gadget *mean_gadgetp, *smoothing_gadgetp, *help_gadgetp;
  143. static struct Gadget *no_smoothing_gadgetp, *sq_smoothing_gadgetp;
  144. static struct Gadget *re_plot_gadgetp, *re_output_gadgetp;
  145. static struct Gadget *time3d_gadgetp, *cut_plots_gadgetp;
  146. static struct Gadget *append_gadgetp, *cal_gadgetp;
  147. static struct Gadget *spectrum_select_gadgetp;
  148.  
  149. static struct Requester *progress_rp = NULL;
  150. static struct Requester *reout_progress_rp = NULL;
  151.  
  152. APTR *last_address = NULL;
  153.  
  154. #define DONT_KNOW -1
  155. static ULONG bins_used = DONT_KNOW;
  156. static wb_append_on = FALSE;
  157.  
  158. BOOLEAN Tooltype_Errors_Reported = FALSE;
  159.  
  160. /*
  161.  * local functions
  162.  */
  163. static void message__set (int message_number);
  164. static void octave_buttons__set (void);
  165. static void fdep_buttons__enable (void);
  166. static void window_buttons__set (void);
  167. static void read_parameters__set (void);
  168. static void rate_gadget__update (void);
  169. static void amplitude__set (void);
  170. static void bins_gadget__update (BOOLEAN force_update);
  171. static void bins_string__set (char *buffer);
  172. static void high_f_gadget__update (void);
  173. static void low_f_gadget__update (void);
  174. static void do_help (struct Gadget *gadgetp);
  175. static char *wb_set_append (char *arguments);
  176. static char *wb_no_set_append (char *arguments);
  177.  
  178. int workbench_dialog (void)
  179. {
  180.     int next_action = WORKBENCH_MODE;
  181.     struct IntuiMessage *message;
  182.     APTR *address = NULL;
  183.     ULONG class = NULL;
  184.     UWORD qualifier = NULL;
  185.     UWORD code = NULL;
  186.     APTR next_address = NULL;
  187.     ULONG next_class = NULL;
  188.     UWORD next_code = NULL;
  189.     UWORD next_qualifier = NULL;
  190.     BOOLEAN last_plot;
  191.     char channel_string[20];
  192.     char rate_string[32];
  193.     char bins_string[20];
  194.     char low_f_string[32];
  195.     char high_f_string[32];
  196.     char smoothing_string[20];
  197.     char copyright_string[132];
  198.     int copyright_indent;
  199.     int copyright_delta;
  200.     int last_command_mode = CommandMode;
  201.     APTR string_gadget_being_set = NULL;
  202.     double s_rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  203.  
  204.     last_plot = Plot;
  205.     Plot = ANY_PLOT;
  206.  
  207.  
  208.     if (dialog_window_p == NULL)
  209.     {
  210.     open_libraries ();
  211.     setup_window_defaults (BUTTON_ROWS);
  212.     gadget__begin (NULL);  /* Ensure requester mode off */
  213.  
  214.     /*
  215.      * Define the Gadgets
  216.      */
  217.  
  218.  
  219.     /* Top Row */
  220.  
  221.     strcpy (copyright_string, NameAuthor);
  222.     strcat (copyright_string, VersionData);
  223.     strcat (copyright_string, " "); /* One space */
  224.     strcat (copyright_string, Copyright);
  225.     copyright_delta = MAX_TEXT_COLS - strlen (copyright_string);
  226.     if (1 & copyright_delta)
  227.     {
  228.         strcpy (copyright_string, NameAuthor);
  229.         strcat (copyright_string, VersionData);
  230.         strcat (copyright_string, "  "); /* Two spaces */
  231.         strcat (copyright_string, Copyright);
  232.     }
  233.     copyright_delta = MAX_TEXT_COLS - strlen (copyright_string);
  234.     copyright_indent = copyright_delta / 2;
  235.  
  236.     copyright_gadgetp = action_button__new (copyright_string,
  237.                              copyright_indent, 0);
  238.  
  239.     copyright_gadgetp->UserData = "Workbench Copyright";
  240.  
  241.     /* Second Row */
  242.  
  243.     help_gadgetp = action_button__new ("Help", 0, 1);
  244.     help_gadgetp->UserData = "Workbench Help";
  245.  
  246.     read_file_gadgetp = string_gadget__new ("Sample File:", ReadName,
  247.                         MAX_PATH, 49, 6, 1);
  248.     read_file_gadgetp->UserData = "Workbench Sample-File";
  249.  
  250.     select_read_gadgetp = action_button__new ("Select", 57, 1);
  251.     select_read_gadgetp->UserData = "Workbench Sample-Select";
  252.  
  253.     con_read_gadgetp = action_button__new ("con:", 65, 1);
  254.     con_read_gadgetp->UserData = "Workbench Sample-Con:";
  255.  
  256.     next_gadgetp = action_button__new ("Next", 71, 1);
  257.     next_gadgetp->UserData = "Workbench Next";
  258.     if (num_files <= 0 ||
  259.         num_files <= file_index + 1)
  260.     {
  261.         next_gadgetp->Flags |= GADGDISABLED;
  262.     }
  263.  
  264.  
  265.  
  266.     /* Third Row */
  267.  
  268.     octave_low_gadgetp = labeled_radio_button__new 
  269.       ("Octave:", "Low", 0, 2);
  270.     octave_2_gadgetp = radio_button__new ("2", 14, 2);
  271.     octave_3_gadgetp = radio_button__new ("3", 17, 2);
  272.     octave_4_gadgetp = radio_button__new ("4", 20, 2);
  273.     octave_5_gadgetp = radio_button__new ("5", 23, 2);
  274.     octave_6_gadgetp = radio_button__new ("6", 26, 2);
  275.     octave_7_gadgetp = radio_button__new ("7", 29, 2);
  276.     octave_hi_gadgetp = radio_button__new ("Hi", 32, 2);
  277.  
  278.     octave_low_gadgetp->UserData = "Workbench Octave-Low";
  279.     octave_2_gadgetp->UserData = "Workbench Octave-2";
  280.     octave_3_gadgetp->UserData = "Workbench Octave-3";
  281.     octave_4_gadgetp->UserData = "Workbench Octave-4";
  282.     octave_5_gadgetp->UserData = "Workbench Octave-5";
  283.     octave_6_gadgetp->UserData = "Workbench Octave-6";
  284.     octave_7_gadgetp->UserData = "Workbench Octave-7";
  285.     octave_hi_gadgetp->UserData = "Workbench Octave-Hi";
  286.  
  287.     one_shot_gadgetp = radio_button__new ("One-Shot Only", 37, 2);
  288.     one_shot_gadgetp->UserData = "Workbench One-Shot-Only";
  289.  
  290.     repeat_only_gadgetp = radio_button__new ("Repeat O", 52, 2);
  291.     repeat_only_gadgetp->UserData = "Workbench Repeat-Only";
  292.  
  293.     sprintf (channel_string,"%d",Channel);
  294.     channel_gadgetp = string_gadget__new ("Channel:", channel_string,
  295.                           2, 13, 62, 2);
  296.     channel_gadgetp->UserData = "Workbench Channel";
  297.  
  298.     /* Fourth Row */
  299.  
  300.     
  301.     if (s_rate != AUTO_RATE && s_rate != INVALID_RATE)
  302.     {
  303.         sprintf (rate_string, "%g", s_rate);
  304.     }
  305.     else
  306.     {
  307.         rate_string[0] = '\0';
  308.     }
  309.     rate_gadgetp = string_gadget__new ("S Rate:", rate_string,
  310.                        30, 20, 0, 3);
  311.     rate_gadgetp->UserData = "Workbench Rate";
  312.  
  313.     bins_string__set (bins_string);
  314.     bins_gadgetp = string_gadget__new ("Bins:", bins_string,
  315.                        12, 16, 22, 3);
  316.     bins_gadgetp->UserData = "Workbench Bins";
  317.  
  318.     bins_max_gadgetp = radio_button__new ("MAX", 40, 3);
  319.     bins_max_gadgetp->UserData = "Workbench Bins-Max";
  320.  
  321.     overlap_gadgetp = radio_button__new ("Overlap", 46, 3);
  322.     overlap_gadgetp->UserData = "Workbench Overlap";
  323.  
  324.     cal_gadgetp = action_button__new ("Cal & Mag", 56, 3);
  325.     cal_gadgetp->UserData = "Workbench Cal-&-Mag";
  326.  
  327.     time3d_gadgetp = action_button__new ("3D-Time", 68, 3);
  328.     time3d_gadgetp->UserData = "Workbench 3D-Time";
  329.  
  330.  
  331.     /* Fifth Row */
  332.  
  333.     rectangle_gadgetp = labeled_radio_button__new 
  334.       ("Window:", "Rectangle ", 0, 4);
  335.     triangle_gadgetp = radio_button__new ("Triangle", 21, 4);
  336.     parzen_gadgetp = radio_button__new ("Parzen", 31, 4);
  337.     welch_gadgetp = radio_button__new ("Welch", 39, 4);
  338.     hann_gadgetp = radio_button__new ("Hann", 46, 4);
  339.     hamming_gadgetp = radio_button__new ("Hamming", 52, 4);
  340.     b_h_74db_gadgetp = radio_button__new ("B-H 74dB", 61, 4);
  341.     b_h_92db_gadgetp = radio_button__new ("92dB", 71, 4);
  342.  
  343.     rectangle_gadgetp->UserData = "Workbench Rectangle";
  344.     triangle_gadgetp->UserData = "Workbench Triangle";
  345.     parzen_gadgetp->UserData = "Workbench Parzen";
  346.     welch_gadgetp->UserData = "Workbench Welch";
  347.     hann_gadgetp->UserData = "Workbench Hann";
  348.     hamming_gadgetp->UserData = "Workbench Hamming";
  349.     b_h_74db_gadgetp->UserData = "Workbench 74dB-Blackman-Harris";
  350.     b_h_92db_gadgetp->UserData = "Workbench 92dB-Blackman-Harris";
  351.  
  352.  
  353.     /* Sixth Row */
  354.  
  355.  
  356.     if (LowFrequency != LOWEST_FREQUENCY)
  357.     {
  358.         sprintf (low_f_string, "%g", LowFrequency);
  359.     }
  360.     else
  361.     {
  362.         low_f_string[0] = '\0';
  363.     }
  364.     low_f_gadgetp = string_gadget__new ("Low Freq:", low_f_string,
  365.                         30, 22, 0, 5);
  366.     low_f_gadgetp->UserData = "Workbench Low-Frequency";
  367.  
  368.     if (HighFrequency != DBL_MAX)
  369.     {
  370.         sprintf (high_f_string, "%g", HighFrequency);
  371.     }
  372.     else
  373.     {
  374.         if (s_rate != AUTO_RATE && s_rate != INVALID_RATE)
  375.         {
  376.         sprintf (high_f_string, "%g", s_rate / 2);
  377.         }
  378.         else
  379.         {
  380.         high_f_string[0] = '\0';
  381.         }
  382.     }
  383.     high_f_gadgetp = string_gadget__new ("High Freq:", high_f_string,
  384.                          30, 23, 25, 5);
  385.     high_f_gadgetp->UserData = "Workbench High-Frequency";
  386.  
  387.     no_smoothing_gadgetp = radio_button__new ("NO", 73, 5);
  388.     no_smoothing_gadgetp->UserData = "Workbench Smoothing-No";
  389.  
  390.     if (SmoothingSegments != INVALID_SMOOTHING &&
  391.         SmoothingSegments != NO_SMOOTHING)
  392.     {
  393.         sprintf (smoothing_string, "%ld", SmoothingSegments);
  394.     }
  395.     else 
  396.     {
  397.         smoothing_string[0] = '\0';
  398.     }
  399.     smoothing_gadgetp = string_gadget__new ("Smooth:", smoothing_string,
  400.                         12, 17, 50, 5);
  401.     smoothing_gadgetp->UserData = "Workbench Smoothing";
  402.  
  403.     sq_smoothing_gadgetp = radio_button__new ("Sq", 69, 5);
  404.     sq_smoothing_gadgetp->UserData = "workbench Smoothing-Squared";
  405.  
  406.  
  407.     /* Seventh Row */
  408.  
  409.     plot_gadgetp = radio_button__new ("Plot", 0, 6);
  410.     plot_gadgetp->UserData = "Workbench Plot";
  411.  
  412.     combine_plots_gadgetp = radio_button__new ("&", 6, 6);
  413.     combine_plots_gadgetp->UserData = "Workbench Plot-Combine";
  414.  
  415.     cut_plots_gadgetp = action_button__new ("X", 9, 6);
  416.     cut_plots_gadgetp->UserData = "Workbench Plot-Cut";
  417.  
  418.     if (is_temp_file (WriteName))
  419.     {
  420.         write_file_gadgetp = string_gadget__new ("Spectrm File:", 
  421.                              NullString, MAX_PATH, 
  422.                              42, 12, 6);
  423.     }
  424.     else
  425.     {
  426.         write_file_gadgetp = string_gadget__new ("Spectrm File:", 
  427.                              WriteName, MAX_PATH, 
  428.                              42, 12, 6);
  429.     }
  430.     write_file_gadgetp->UserData = "Workbench Spectrum-File";
  431.  
  432.     spectrum_select_gadgetp = action_button__new ("S", 56, 6);
  433.     spectrum_select_gadgetp->UserData = 
  434.       "Workbench Spectrum-File-Select";
  435.  
  436.     append_gadgetp = radio_button__new ("Open", 59, 6);
  437.         append_gadgetp->UserData = "Workbench Spectrum-File-Open";
  438.  
  439.     cancel_write_gadgetp = action_button__new ("Can", 65, 6);
  440.     cancel_write_gadgetp->UserData = "Workbench Spectrum-File-Cancel";
  441.  
  442.     def_write_gadgetp = action_button__new ("*.fft", 70, 6);
  443.     def_write_gadgetp->UserData = "Workbench *.fft";
  444.  
  445.  
  446.     /* Eighth Row */
  447.  
  448.     CLI_gadgetp = action_button__new ("CLI", 0, 7);
  449.     CLI_gadgetp->UserData = "Workbench CLI";
  450.  
  451.     pink_gadgetp = radio_button__new ("Pink", 6, 7);
  452.     pink_gadgetp->UserData = "Workbench Pink";
  453.  
  454.     amplitude_gadgetp = radio_button__new ("Ampl", 13, 7);
  455.     amplitude_gadgetp->UserData = "Workbench Amplitude";
  456.  
  457.     power_gadgetp = radio_button__new ("Power", 19, 7);
  458.     power_gadgetp->UserData = "Workbench Power";
  459.  
  460.     mean_gadgetp = radio_button__new ("Mean", 27, 7);
  461.     mean_gadgetp->UserData = "Workbench Mean";
  462.  
  463.     db_gadgetp = radio_button__new ("dB", 34, 7);
  464.     db_gadgetp->UserData = "Workbench dB";
  465.  
  466.     log_x_gadgetp = radio_button__new ("LogX", 39, 7);
  467.     log_x_gadgetp->UserData = "Workbench Logx";
  468.  
  469.     log_y_gadgetp = radio_button__new ("LogY", 46, 7);
  470.     log_y_gadgetp->UserData = "Workbench Logy";
  471.  
  472. #ifndef ONLY_OK_TALL
  473.     re_plot_gadgetp = tall_action_button__new ("RePlot", 53, 7);
  474. #else
  475.     re_plot_gadgetp = action_button__new ("RePlot", 53, 7);
  476. #endif
  477.     re_plot_gadgetp->UserData = "Workbench RePlot";
  478.  
  479. #ifndef ONLY_OK_TALL
  480.     re_output_gadgetp = tall_action_button__new ("ReOutput", 62, 7);
  481. #else
  482.     re_output_gadgetp = action_button__new ("ReOutput", 62, 7);
  483. #endif
  484.     re_output_gadgetp->UserData = "Workbench ReOutput";
  485.  
  486.     ok_gadgetp = tall_action_button__new ("OK", 73, 7);
  487.     ok_gadgetp->UserData = "Workbench OK";
  488.  
  489.  
  490.     /* Ninth Row */
  491.     /* IMPORTANT!  LAST GADGET MUST APPEAR IN WINDOW INITIALIZATION */
  492.  
  493.     message_gadgetp = message_gadget__new (75, 0, 8);
  494.     message_gadgetp->UserData = "Workbench Message";
  495.  
  496.     /*
  497.      * Now, create the Window
  498.      */
  499.     dialog_window_p = window__new (Dialog_Window_Title);
  500.     }
  501.  
  502.     CommandMode = WORKBENCH_MODE;
  503.  
  504. /*
  505.  * Set up gadgets with current info
  506.  */
  507.     if (Overlap) radio_button__in (overlap_gadgetp, dialog_window_p);
  508.     if (OneShotOnly) radio_button__in (one_shot_gadgetp, dialog_window_p);
  509.     if (RepeatOnly) radio_button__in (repeat_only_gadgetp, dialog_window_p);
  510.     if (SquaredSmoothing) radio_button__in (sq_smoothing_gadgetp, 
  511.                         dialog_window_p);
  512.     if (Plot != NO_PLOT) radio_button__in (plot_gadgetp, dialog_window_p);
  513.     if (CombinePlots) radio_button__in (combine_plots_gadgetp, 
  514.                     dialog_window_p);
  515.     if (Pink) radio_button__in (pink_gadgetp, dialog_window_p);
  516.     if (Mean) radio_button__in (mean_gadgetp, dialog_window_p);
  517.     if (Db) radio_button__in (db_gadgetp, dialog_window_p);
  518.     if (LogX) radio_button__in (log_x_gadgetp, dialog_window_p);
  519.     if (LogY) radio_button__in (log_y_gadgetp, dialog_window_p);
  520.     if (NumberBins == MAX_BINS) radio_button__in (bins_max_gadgetp,
  521.                           dialog_window_p);
  522.     amplitude__set ();
  523.     if (SmoothingSegments == NO_SMOOTHING)
  524.     {
  525.     radio_button__in (no_smoothing_gadgetp, dialog_window_p);
  526.     }
  527.     window_buttons__set ();
  528.     octave_buttons__set ();
  529.  
  530. /* I've been driven to this by lack of support */
  531.     workbench_nag_requester ();
  532.  
  533.  
  534.     if (Tooltype_Errors && !Tooltype_Errors_Reported)
  535.     {
  536.     error_message (TOOLTYPE_ERROR);
  537.     Tooltype_Errors_Reported = TRUE;
  538.     }
  539.  
  540.     if (ReadName && strlen(ReadName))
  541.     {
  542.     read_parameters__set ();
  543.     message__set (SELECT_PARAMETERS);
  544.     }
  545.     else
  546.     {
  547.     message__set (SELECT_READ_FILE);
  548.     }
  549.  
  550. /* Handle events */
  551.  
  552.     while (TRUE)
  553.     {
  554.     chkabort ();
  555.     Wait (1 << dialog_window_p->UserPort->mp_SigBit);
  556.     while (message = (struct IntuiMessage *) GetMsg 
  557.            (dialog_window_p->UserPort))
  558.     {
  559.         class = message->Class;
  560.         address = message->IAddress;
  561.         qualifier = message->Qualifier;
  562.         code = message->Code;
  563.         ReplyMsg ((struct Message *) message);
  564.     /*
  565.      * IDCMP_CLOSEWINDOW doesn't have an IAddress
  566.          * so must be handled here.
  567.          */
  568.         if (class == IDCMP_CLOSEWINDOW) goto closewindow;
  569.         /*
  570.          * Finish unfinished string
  571.          */
  572.  
  573.         if (string_gadget_being_set &&
  574.         string_gadget_being_set != address && !
  575.         (string_gadget_being_set == read_file_gadgetp &&
  576.          (address == (APTR) select_read_gadgetp) ||
  577.          (address == (APTR) con_read_gadgetp)))
  578.         {
  579.         next_address = address;
  580.         next_class = class;
  581.         next_qualifier = qualifier;
  582.         next_code = code;
  583.  
  584.         address = string_gadget_being_set;
  585.         class = IDCMP_GADGETUP;
  586.         qualifier = NULL;
  587.         code = NULL;
  588.         }
  589.         string_gadget_being_set = NULL;
  590.  
  591.         while (address)
  592.         {
  593.         CATCH_ERROR;
  594.         /*
  595.              * Here begins massive compound if statement
  596.              */
  597.         if (class == IDCMP_RAWKEY)
  598.         {
  599.             /* Test for HELP key on keyboard...
  600.                  * At present, I'm not happy with the way this works.
  601.          * If a string gadget is activated, there is no response.
  602.                  * So, I'm leaving it as undocumented, maybe it will
  603.                  *   help someone anyway.  Meanwhile there is a help
  604.                  *   button which does the same thing.
  605.                  */
  606.             if (code == RAW_HELP_KEY)
  607.             {
  608.             workbench_help_requester ();
  609.             }
  610.         } /* end if class == IDCMP_RAWKEY */
  611.  
  612.         else if (qualifier & IEQUALIFIER_CONTROL)
  613.         {
  614.                 /*
  615.                  * CTRL and any gadget select gives help on that gadget
  616.          */
  617.             do_help ((struct Gadget *) address);
  618.         }
  619.         /*
  620.              * Check for string GADGETDOWN
  621.          */
  622.         else if (class == IDCMP_GADGETDOWN && 
  623.              ((struct Gadget *) address)->GadgetType &
  624.              GTYP_STRGADGET)
  625.         {
  626.             string_gadget_being_set = address;
  627.         }
  628.         else if (address == (APTR) help_gadgetp)
  629.         {
  630.             workbench_help_requester ();
  631.         }
  632.         else if (address == (APTR) ok_gadgetp)
  633.         {
  634.             ULONG check_frames = FileFrames;
  635.  
  636.             message__set (PERFORMING_FFT);
  637.             CATCH_ERROR
  638.             {
  639. #ifdef NO_PROGRESS
  640.             ok (NullString);
  641.             loop_time_message_done (LoopTimeElapsed);
  642. #else
  643.                 if (!progress_rp)
  644.               progress_rp = progress_requester__new 
  645.                 (Attempting_to_Perform_FFT_S, 50);
  646.             progress_requester__apply (progress_rp,
  647.                            ok,
  648.                            NullString,
  649.                            dialog_window_p);
  650.             loop_time_message_done (LoopTimeElapsed);
  651. #endif
  652.             }
  653.             ON_ERROR
  654.             {
  655.             message__set (REMEMBER_MESSAGE);
  656.             }
  657.             END_CATCH_ERROR;
  658.  
  659.             if (check_frames != FileFrames)
  660.             {  /* A file scan has occurred */
  661.             bins_gadget__update (FALSE);
  662.             }
  663.         }
  664.         else if (address == (APTR) CLI_gadgetp)
  665.         {
  666.             next_action = INTERACTIVE_MODE;
  667.             goto closewindow;
  668.         }
  669.         else if (address == (APTR) copyright_gadgetp)
  670.         {
  671.             copyright_requester ();
  672.         }
  673.         else if (address == (APTR) cal_gadgetp)
  674.         {
  675.             calibration_requester ();
  676.         }
  677.         else if (address == (APTR) time3d_gadgetp)
  678.         {
  679.             time3d_requester ();
  680.             bins_gadget__update (FALSE);
  681.         }
  682.         else if (address == (APTR) rectangle_gadgetp)
  683.         {
  684.             set_rectangle (NullString);
  685.             window_buttons__set ();
  686.         }
  687.         else if (address == (APTR) triangle_gadgetp)
  688.         {
  689.             set_triangle (NullString);
  690.             window_buttons__set ();
  691.         }
  692.         else if (address == (APTR) parzen_gadgetp)
  693.         {
  694.             set_parzen (NullString);
  695.             window_buttons__set ();
  696.         }
  697.         else if (address == (APTR) welch_gadgetp)
  698.         {
  699.             set_welch (NullString);
  700.             window_buttons__set ();
  701.         }
  702.         else if (address == (APTR) hann_gadgetp)
  703.         {
  704.             set_hann (NullString);
  705.             window_buttons__set ();
  706.         }
  707.         else if (address == (APTR) hamming_gadgetp)
  708.         {
  709.             set_hamming (NullString);
  710.             window_buttons__set ();
  711.         }
  712.         else if (address == (APTR) b_h_74db_gadgetp)
  713.         {
  714.             set_blackman_harris_74db (NullString);
  715.             window_buttons__set ();
  716.         }
  717.         else if (address == (APTR) b_h_92db_gadgetp)
  718.         {
  719.             set_blackman_harris_92db (NullString);
  720.             window_buttons__set ();
  721.         }
  722.         else if (address == (APTR) one_shot_gadgetp)
  723.         {
  724.             if (one_shot_gadgetp->Flags & SELECTED)
  725.             {
  726.             set_no_one_shot_only (NullString);
  727.             radio_button__out (one_shot_gadgetp,
  728.                        dialog_window_p);
  729.             }
  730.             else
  731.             {
  732.             set_one_shot_only (NullString);
  733.             radio_button__in (one_shot_gadgetp,
  734.                       dialog_window_p);
  735.             radio_button__out (repeat_only_gadgetp,
  736.                        dialog_window_p);
  737.             }
  738.             bins_gadget__update (FALSE);
  739.         }
  740.         else if (address == (APTR) repeat_only_gadgetp)
  741.         {
  742.             if (repeat_only_gadgetp->Flags & SELECTED)
  743.             {
  744.             set_no_repeat_only (NullString);
  745.             radio_button__out (repeat_only_gadgetp,
  746.                        dialog_window_p);
  747.             }
  748.             else
  749.             {
  750.             set_repeat_only (NullString);
  751.             radio_button__in (repeat_only_gadgetp,
  752.                       dialog_window_p);
  753.             radio_button__out (one_shot_gadgetp,
  754.                        dialog_window_p);
  755.             }
  756.             bins_gadget__update (FALSE);
  757.         }
  758. /*        else if (address == (APTR) pad_gadgetp) */
  759. /*        { */
  760. /*            radio_button__toggle (pad_gadgetp, set_pad,  */
  761. /*                       set_no_pad, */
  762. /*                       dialog_window_p); */
  763. /*            bins_gadget__update (FALSE); */
  764. /*        } */
  765.         else if (address == (APTR) channel_gadgetp)
  766.         {
  767.             char *buffer = string_gadget__apply 
  768.               (channel_gadgetp, set_channel);
  769.             if (!strlen (buffer))
  770.             {
  771.             sprintf (buffer, "%d", Channel);
  772.             refresh_gadget (channel_gadgetp,
  773.                     dialog_window_p);
  774.             }
  775.         }
  776.         else if (address == (APTR) rate_gadgetp)
  777.         {
  778.             char *buffer = string_gadget__apply 
  779.               (rate_gadgetp, set_rate);
  780.             if (!strlen (buffer))
  781.             {
  782.             rate_gadget__update ();
  783.             }
  784.             high_f_gadget__update ();
  785.             message__set (SELECT_PARAMETERS);
  786.         }
  787.         else if (address == (APTR) bins_max_gadgetp)
  788.         {
  789.             set_bins (NullString);
  790.             radio_button__in (bins_max_gadgetp,
  791.                       dialog_window_p);
  792.             bins_gadget__update (TRUE);  /* Force */
  793.         }
  794.         else if (address == (APTR) bins_gadgetp)
  795.         {
  796.             char *buffer = string_gadget__apply 
  797.               (bins_gadgetp, set_bins);
  798.             if (strlen (buffer))
  799.             {
  800.             radio_button__out (bins_max_gadgetp,
  801.                        dialog_window_p);
  802.             }
  803.             else
  804.             {
  805.             radio_button__in (bins_max_gadgetp,
  806.                       dialog_window_p);
  807.             }
  808.             
  809.             bins_gadget__update (TRUE);  /* Force */
  810.         }
  811.         else if (address == (APTR) no_smoothing_gadgetp)
  812.         {
  813.             struct StringInfo *string_infop = 
  814.               smoothing_gadgetp->SpecialInfo;
  815.             char *buffer = string_infop->Buffer;
  816.             buffer[0] = '\0';
  817.             refresh_gadget (smoothing_gadgetp,
  818.                     dialog_window_p);
  819.             radio_button__in (no_smoothing_gadgetp,
  820.                       dialog_window_p);
  821.             set_smoothing_segments (NullString);
  822.         }
  823.         else if (address == (APTR) smoothing_gadgetp)
  824.         {
  825.             char *buffer = string_gadget__apply 
  826.               (smoothing_gadgetp, set_smoothing_segments);
  827.             if (strlen (buffer))
  828.             {
  829.             radio_button__out (no_smoothing_gadgetp,
  830.                        dialog_window_p);
  831.             }
  832.             else
  833.             {
  834.             radio_button__in (no_smoothing_gadgetp,
  835.                       dialog_window_p);
  836.             }
  837.             
  838.         }
  839.         else if (address == (APTR) sq_smoothing_gadgetp)
  840.         {
  841.             radio_button__toggle (sq_smoothing_gadgetp,
  842.                        set_squared_smoothing, 
  843.                        set_no_squared_smoothing,
  844.                        dialog_window_p);
  845.         }
  846.         else if (address == (APTR) octave_low_gadgetp)
  847.         {
  848.             Octave = 1;
  849.             octave_buttons__set ();
  850.             bins_gadget__update (FALSE);
  851.         }
  852.         else if (address == (APTR) octave_2_gadgetp)
  853.         {
  854.             Octave = 2;
  855.             octave_buttons__set ();
  856.             bins_gadget__update (FALSE);
  857.         }
  858.         else if (address == (APTR) octave_3_gadgetp)
  859.         {
  860.             Octave = 3;
  861.             octave_buttons__set ();
  862.             bins_gadget__update (FALSE);
  863.         }
  864.         else if (address == (APTR) octave_4_gadgetp)
  865.         {
  866.             Octave = 4;
  867.             octave_buttons__set ();
  868.             bins_gadget__update (FALSE);
  869.         }
  870.         else if (address == (APTR) octave_5_gadgetp)
  871.         {
  872.             Octave = 5;
  873.             octave_buttons__set ();
  874.             bins_gadget__update (FALSE);
  875.         }
  876.         else if (address == (APTR) octave_6_gadgetp)
  877.         {
  878.             Octave = 6;
  879.             octave_buttons__set ();
  880.             bins_gadget__update (FALSE);
  881.         }
  882.         else if (address == (APTR) octave_7_gadgetp)
  883.         {
  884.             Octave = 7;
  885.             octave_buttons__set ();
  886.             bins_gadget__update (FALSE);
  887.         }
  888.         else if (address == (APTR) octave_hi_gadgetp)
  889.         {
  890.             Octave = 0;
  891.             octave_buttons__set ();
  892.             bins_gadget__update (FALSE);
  893.         }
  894.         else if (address == (APTR) next_gadgetp)
  895.         {
  896.             next_action = NEXT_FILE;
  897.             goto closewindow;
  898.         }
  899.         else if (address == (APTR) select_read_gadgetp)
  900.         {
  901.             char *read_file = file_requestor 
  902.               ("Select Sample File");
  903.             if (read_file)
  904.             {
  905.             string_gadget__reset (read_file_gadgetp, read_file,
  906.                           dialog_window_p);
  907.             name_string_gadget__apply (read_file_gadgetp,
  908.                            set_read);
  909.             read_parameters__set ();
  910.             }
  911.             else
  912.             {
  913.             message__set (SELECT_READ_FILE);
  914.             }
  915.             gfree (read_file);
  916.         }
  917.         else if (address == (APTR) con_read_gadgetp)
  918.         {
  919.             set_read ("con:");
  920.             string_gadget__reset (read_file_gadgetp, "con:",
  921.                       dialog_window_p);
  922.             read_parameters__set ();
  923.         }
  924.         else if (address == (APTR) read_file_gadgetp)
  925.         {
  926.             CATCH_ERROR
  927.             {
  928.             name_string_gadget__apply (read_file_gadgetp, 
  929.                           set_read);
  930.             read_parameters__set ();
  931.             }
  932.             ON_ERROR
  933.             {
  934.             message__set (SELECT_READ_FILE);
  935.             }
  936.             END_CATCH_ERROR;
  937.         }
  938.         else if (address == (APTR) low_f_gadgetp)
  939.         {
  940.             char *buffer = string_gadget__apply 
  941.               (low_f_gadgetp, set_low_frequency);
  942.             if (!strlen (buffer))
  943.             {
  944.             low_f_gadget__update ();
  945.             }
  946.         }
  947.         else if (address == (APTR) high_f_gadgetp)
  948.         {
  949.             char *buffer = string_gadget__apply 
  950.               (high_f_gadgetp, set_high_frequency);
  951.             if (!strlen (buffer))
  952.             {
  953.             high_f_gadget__update ();
  954.             }
  955.         }
  956.         else if (address == (APTR) write_file_gadgetp)
  957.         {
  958.             if (wb_append_on)
  959.             {
  960.             name_string_gadget__apply (write_file_gadgetp,
  961.                            set_append);
  962.             }
  963.             else
  964.             {
  965.             name_string_gadget__apply (write_file_gadgetp,
  966.                            set_write);
  967.             }
  968.         }
  969.         else if (address == (APTR) spectrum_select_gadgetp)
  970.         {
  971.             char *spectrum_file = file_requestor
  972.               ("Select Spectrum File");
  973.             if (spectrum_file)
  974.             {
  975.             /* default now to append mode; usually helps */
  976.             radio_button__in (append_gadgetp, dialog_window_p);
  977.             wb_set_append (NullString);
  978.             string_gadget__reset (write_file_gadgetp, 
  979.                           spectrum_file,
  980.                           dialog_window_p);
  981.             if (wb_append_on)
  982.             {
  983.                 name_string_gadget__apply (write_file_gadgetp,
  984.                                set_append);
  985.             }
  986.             else
  987.             {
  988.                 name_string_gadget__apply (write_file_gadgetp,
  989.                                set_write);
  990.             }
  991.             }
  992.         }
  993.         else if (address == (APTR) append_gadgetp)
  994.         {
  995.             radio_button__toggle (append_gadgetp,
  996.                        wb_set_append, wb_no_set_append,
  997.                        dialog_window_p);
  998.         }
  999.         else if (address == (APTR) cancel_write_gadgetp)
  1000.         {
  1001.             string_gadget__reset (write_file_gadgetp,
  1002.                       NullString, dialog_window_p);
  1003.             if (wb_append_on)
  1004.             {
  1005.             set_append (NullString);
  1006.             }
  1007.             else
  1008.             {
  1009.             set_write (NullString);
  1010.             }
  1011.         }
  1012.         else if (address == (APTR) def_write_gadgetp)
  1013.         {
  1014.             struct StringInfo *string_infop = 
  1015.               write_file_gadgetp->SpecialInfo;
  1016.             char *buffer = string_infop->Buffer;
  1017.             if (ReadName)
  1018.             {
  1019.             strcpy (buffer, ReadName);
  1020.             strcat (buffer, ".fft");
  1021.             }
  1022.             else
  1023.             {
  1024.             strcpy (buffer, ".fft");
  1025.             }
  1026.             string_infop->NumChars = strlen (buffer);
  1027.             if (wb_append_on)
  1028.             {
  1029.             name_string_gadget__apply (write_file_gadgetp,
  1030.                            set_append);
  1031.             }
  1032.             else
  1033.             {
  1034.             name_string_gadget__apply (write_file_gadgetp,
  1035.                            set_write);
  1036.             }
  1037.             refresh_gadget (write_file_gadgetp, 
  1038.                     dialog_window_p);
  1039.         }
  1040.         else if (address == (APTR) amplitude_gadgetp)
  1041.         {
  1042.             set_amplitude (NullString);
  1043.             amplitude__set ();
  1044.         }
  1045.         else if (address == (APTR) power_gadgetp)
  1046.         {
  1047.             set_power (NullString);
  1048.             amplitude__set ();
  1049.         }
  1050.         else if (address == (APTR) overlap_gadgetp)
  1051.         {
  1052.             radio_button__toggle (overlap_gadgetp,
  1053.                        set_overlap, set_no_overlap,
  1054.                        dialog_window_p);
  1055.         }
  1056.         else if (address == (APTR) db_gadgetp)
  1057.         {
  1058.             radio_button__toggle (db_gadgetp, 
  1059.                        set_db, set_no_db,
  1060.                        dialog_window_p);
  1061.         }
  1062.         else if (address == (APTR) pink_gadgetp)
  1063.         {
  1064.             radio_button__toggle (pink_gadgetp, set_pink, 
  1065.                        set_no_pink,
  1066.                        dialog_window_p);
  1067.         }
  1068.         else if (address == (APTR) mean_gadgetp)
  1069.         {
  1070.             radio_button__toggle (mean_gadgetp, set_mean, 
  1071.                        set_sum, 
  1072.                        dialog_window_p);
  1073.         }
  1074.         else if (address == (APTR) plot_gadgetp)
  1075.         {
  1076.             radio_button__toggle (plot_gadgetp, set_plot, 
  1077.                        set_no_plot,
  1078.                        dialog_window_p);
  1079.             last_plot = Plot;
  1080.         }
  1081.         else if (address == (APTR) combine_plots_gadgetp)
  1082.         {
  1083.             radio_button__toggle (combine_plots_gadgetp,
  1084.                        set_combine_plots,
  1085.                        set_no_combine_plots,
  1086.                        dialog_window_p);
  1087.         }
  1088.         else if (address == (APTR) cut_plots_gadgetp)
  1089.         {
  1090.             cut_combined_plot (NullString);
  1091.         }
  1092.         else if (address == (APTR) re_output_gadgetp)
  1093.         {
  1094.  
  1095.             extern double Ending_Progress; /* from ok_spectrum() */
  1096.             if (!reout_progress_rp)
  1097.               reout_progress_rp = progress_requester__new
  1098.             ("Rewriting spectrum file...", 50);
  1099.             Ending_Progress = 99.0;
  1100.             progress_requester__apply (reout_progress_rp,
  1101.                            re_output,
  1102.                            NullString,
  1103.                            dialog_window_p);
  1104.         }
  1105.         else if (address == (APTR) re_plot_gadgetp)
  1106.         {
  1107.             re_plot (NullString);
  1108.         }
  1109.         else if (address == (APTR) log_x_gadgetp)
  1110.         {
  1111.             radio_button__toggle (log_x_gadgetp, set_logx, 
  1112.                        set_no_logx,
  1113.                        dialog_window_p);
  1114.         }
  1115.         else if (address == (APTR) log_y_gadgetp)
  1116.         {
  1117.             radio_button__toggle (log_y_gadgetp, set_logy,
  1118.                        set_no_logy,
  1119.                        dialog_window_p);
  1120.         } /* end massive compound if*/
  1121.         END_CATCH_ERROR;
  1122.  
  1123.         last_address = address;
  1124.         address = next_address;
  1125.         class = next_class;
  1126.         qualifier = next_qualifier;
  1127.         code = next_code;
  1128.  
  1129.         next_address = NULL;
  1130.         next_class = NULL;
  1131.         next_qualifier = NULL;
  1132.         next_code = NULL;
  1133.  
  1134.         } /* end while (address) */
  1135.     } /* end while (message...) */
  1136.     } /* end while (TRUE) */
  1137.  
  1138. closewindow:    
  1139.     CloseWindow (dialog_window_p);
  1140.     dialog_window_p = NULL;
  1141.     if (class == IDCMP_CLOSEWINDOW)
  1142.     {
  1143.     quit (NullString);  /* it all ends here, no matter where started */
  1144.     }
  1145.     CommandMode = last_command_mode;
  1146.     Plot = last_plot;  /* reset previous default, unless changed */
  1147.     return next_action;
  1148. }
  1149.  
  1150. static void amplitude__set (void)
  1151. {
  1152.     if (Amplitude)
  1153.     {
  1154.     radio_button__in (amplitude_gadgetp, dialog_window_p);
  1155.     radio_button__out (power_gadgetp, dialog_window_p);
  1156.     }
  1157.     else
  1158.     {
  1159.     radio_button__in (power_gadgetp, dialog_window_p);
  1160.     radio_button__out (amplitude_gadgetp, dialog_window_p);
  1161.     }
  1162. }
  1163.  
  1164.  
  1165. static void window_buttons__set ()
  1166. {
  1167.     switch (WindowType)
  1168.     {
  1169.     case RECTANGLE_WINDOW:
  1170.     radio_button__in (rectangle_gadgetp, dialog_window_p);
  1171.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1172.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1173.     radio_button__out (welch_gadgetp, dialog_window_p);
  1174.     radio_button__out (hann_gadgetp, dialog_window_p);
  1175.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1176.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1177.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1178.     break;
  1179.     case TRIANGLE_WINDOW:
  1180.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1181.     radio_button__in (triangle_gadgetp, dialog_window_p);
  1182.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1183.     radio_button__out (welch_gadgetp, dialog_window_p);
  1184.     radio_button__out (hann_gadgetp, dialog_window_p);
  1185.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1186.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1187.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1188.     break;
  1189.     case PARZEN_WINDOW:
  1190.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1191.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1192.     radio_button__in (parzen_gadgetp, dialog_window_p);
  1193.     radio_button__out (welch_gadgetp, dialog_window_p);
  1194.     radio_button__out (hann_gadgetp, dialog_window_p);
  1195.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1196.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1197.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1198.     break;
  1199.     case WELCH_WINDOW:
  1200.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1201.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1202.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1203.     radio_button__in (welch_gadgetp, dialog_window_p);
  1204.     radio_button__out (hann_gadgetp, dialog_window_p);
  1205.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1206.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1207.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1208.     break;
  1209.     case HANN_WINDOW:
  1210.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1211.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1212.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1213.     radio_button__out (welch_gadgetp, dialog_window_p);
  1214.     radio_button__in (hann_gadgetp, dialog_window_p);
  1215.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1216.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1217.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1218.     break;
  1219.     case HAMMING_WINDOW:
  1220.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1221.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1222.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1223.     radio_button__out (welch_gadgetp, dialog_window_p);
  1224.     radio_button__out (hann_gadgetp, dialog_window_p);
  1225.     radio_button__in (hamming_gadgetp, dialog_window_p);
  1226.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1227.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1228.     break;
  1229.     case BLACKMAN_HARRIS_74DB_WINDOW:
  1230.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1231.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1232.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1233.     radio_button__out (welch_gadgetp, dialog_window_p);
  1234.     radio_button__out (hann_gadgetp, dialog_window_p);
  1235.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1236.     radio_button__in (b_h_74db_gadgetp, dialog_window_p);
  1237.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1238.     break;
  1239.     case BLACKMAN_HARRIS_92DB_WINDOW:
  1240.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1241.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1242.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1243.     radio_button__out (welch_gadgetp, dialog_window_p);
  1244.     radio_button__out (hann_gadgetp, dialog_window_p);
  1245.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1246.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1247.     radio_button__in (b_h_92db_gadgetp, dialog_window_p);
  1248.     break;
  1249.     }
  1250. }
  1251.  
  1252. static void fdep_buttons__enable (void)
  1253. {
  1254.     BOOLEAN changed_value = FALSE;
  1255.     BOOLEAN no_one_shot_frames = TRUE;
  1256.     BOOLEAN no_repeat_frames = TRUE;
  1257.  
  1258.     if (!ReadPtr) return;
  1259.  
  1260.     switch (FileOctaves)
  1261.     {
  1262.     case 7:
  1263.     gadget__enable (octave_7_gadgetp, dialog_window_p);
  1264.     case 6:
  1265.     gadget__enable (octave_6_gadgetp, dialog_window_p);
  1266.     case 5:
  1267.     gadget__enable (octave_5_gadgetp, dialog_window_p);
  1268.     case 4:
  1269.     gadget__enable (octave_4_gadgetp, dialog_window_p);
  1270.     case 3:
  1271.     gadget__enable (octave_3_gadgetp, dialog_window_p);
  1272.     case 2:
  1273.     gadget__enable (octave_2_gadgetp, dialog_window_p);
  1274.     }
  1275.  
  1276.     switch (FileOctaves)
  1277.     {
  1278.     case 1:
  1279.     gadget__disable (octave_2_gadgetp, dialog_window_p);
  1280.     case 2:
  1281.     gadget__disable (octave_3_gadgetp, dialog_window_p);
  1282.     case 3:
  1283.     gadget__disable (octave_4_gadgetp, dialog_window_p);
  1284.     case 4:
  1285.     gadget__disable (octave_5_gadgetp, dialog_window_p);
  1286.     case 5:
  1287.     gadget__disable (octave_6_gadgetp, dialog_window_p);
  1288.     case 6:
  1289.     gadget__disable (octave_7_gadgetp, dialog_window_p);
  1290.     }
  1291.  
  1292.     if (FileChannels > 1)
  1293.     {
  1294.     gadget__enable  (channel_gadgetp, dialog_window_p);
  1295.     }
  1296.     else
  1297.     {
  1298.     if (Channel > 1)
  1299.     {
  1300.         set_channel (NullString);
  1301.         string_gadget__reset (channel_gadgetp, "1", dialog_window_p);
  1302.         changed_value = TRUE;
  1303.     }
  1304.     gadget__disable (channel_gadgetp, dialog_window_p);
  1305.     }
  1306.  
  1307.     if (FileFormat == ID_8SVX)
  1308.     {
  1309.     if (FileOneShotHiFrames)
  1310.     {
  1311.         gadget__enable (one_shot_gadgetp, dialog_window_p);
  1312.         no_one_shot_frames = FALSE;
  1313.     }
  1314.     if (FileRepeatHiFrames)
  1315.     {
  1316.         gadget__enable (repeat_only_gadgetp, dialog_window_p);
  1317.         no_repeat_frames = FALSE;
  1318.     }
  1319.     }
  1320.     if (no_one_shot_frames)
  1321.     {
  1322.     if (OneShotOnly)
  1323.     {
  1324.         set_no_one_shot_only (NullString);
  1325.         radio_button__out (one_shot_gadgetp, dialog_window_p);
  1326.         changed_value = TRUE;
  1327.     }
  1328.     gadget__disable (one_shot_gadgetp, dialog_window_p);
  1329.     }
  1330.     if (no_repeat_frames)
  1331.     {
  1332.     if (RepeatOnly)
  1333.     {
  1334.         set_no_repeat_only (NullString);
  1335.         radio_button__out (repeat_only_gadgetp, dialog_window_p);
  1336.         changed_value = TRUE;
  1337.     }
  1338.     gadget__disable (repeat_only_gadgetp, dialog_window_p);
  1339.     }
  1340.  
  1341.     if (changed_value)
  1342.     {
  1343.     error_message (CHANGED_FORMAT_DEP_VALUE);
  1344.     }
  1345. }
  1346.  
  1347.  
  1348. static void octave_buttons__set (void)
  1349. {
  1350.     switch (Octave)
  1351.     {
  1352.     case 0:
  1353.     radio_button__in (octave_hi_gadgetp, dialog_window_p);
  1354.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1355.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1356.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1357.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1358.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1359.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1360.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1361.     break;
  1362.     case 1:
  1363.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1364.     radio_button__in (octave_low_gadgetp, dialog_window_p);
  1365.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1366.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1367.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1368.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1369.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1370.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1371.     break;
  1372.     case 2:
  1373.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1374.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1375.     radio_button__in (octave_2_gadgetp, dialog_window_p);
  1376.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1377.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1378.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1379.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1380.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1381.     break;
  1382.     case 3:
  1383.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1384.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1385.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1386.     radio_button__in (octave_3_gadgetp, dialog_window_p);
  1387.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1388.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1389.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1390.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1391.     break;
  1392.     case 4:
  1393.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1394.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1395.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1396.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1397.     radio_button__in (octave_4_gadgetp, dialog_window_p);
  1398.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1399.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1400.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1401.     break;
  1402.     case 5:
  1403.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1404.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1405.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1406.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1407.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1408.     radio_button__in (octave_5_gadgetp, dialog_window_p);
  1409.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1410.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1411.     break;
  1412.     case 6:
  1413.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1414.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1415.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1416.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1417.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1418.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1419.     radio_button__in (octave_6_gadgetp, dialog_window_p);
  1420.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1421.     break;
  1422.     case 7:
  1423.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1424.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1425.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1426.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1427.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1428.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1429.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1430.     radio_button__in (octave_7_gadgetp, dialog_window_p);
  1431.     break;
  1432.     }
  1433. }
  1434.  
  1435. static void read_parameters__set (void)
  1436. {
  1437.     if (!ReadName || ReadName == NullString) return;
  1438.     fdep_buttons__enable ();
  1439.     rate_gadget__update ();
  1440.     bins_gadget__update (FALSE);
  1441. /*    low_f_gadget__update (); now included in bins_gadget__update... */
  1442.     high_f_gadget__update ();
  1443.     if (FileFormat != UNFORMATTED)
  1444.     {
  1445.     message__set (SELECT_PARAMETERS);
  1446.     }
  1447.     else if (Rate == AUTO_RATE)
  1448.     {
  1449.     message__set (SET_RATE);
  1450.     }
  1451.     else
  1452.     {
  1453.     message__set (VERIFY_RATE);
  1454.     }
  1455. }
  1456.  
  1457. static void rate_gadget__update (void)
  1458. {
  1459.     double rate;
  1460.     struct StringInfo *string_infop = 
  1461.       rate_gadgetp->SpecialInfo;
  1462.     char *buffer = string_infop->Buffer;
  1463.  
  1464.     rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  1465.     if (rate != AUTO_RATE)
  1466.     {
  1467.         sprintf (buffer,"%g",rate);
  1468.     }
  1469.     else
  1470.     {
  1471.     buffer[0] = '\0';
  1472.     }
  1473.     refresh_gadget (rate_gadgetp, dialog_window_p);
  1474. }
  1475.  
  1476.  
  1477. static void high_f_gadget__update (void)
  1478. {
  1479.     double rate;
  1480.     struct StringInfo *string_infop = 
  1481.       high_f_gadgetp->SpecialInfo;
  1482.     char *buffer = string_infop->Buffer;
  1483.  
  1484.     if (HighFrequency == DBL_MAX)
  1485.     {
  1486.         rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  1487.     if (rate != AUTO_RATE)
  1488.     {
  1489.         sprintf (buffer, "%g", rate / (2 * Interleave));
  1490.         refresh_gadget (high_f_gadgetp, dialog_window_p);
  1491.     }
  1492.     }
  1493. }
  1494.  
  1495. static void low_f_gadget__update (void)
  1496. {
  1497.     double rate;
  1498.     struct StringInfo *string_infop = 
  1499.       low_f_gadgetp->SpecialInfo;
  1500.     char *buffer = string_infop->Buffer;
  1501.     BOOLEAN reset = FALSE;
  1502.  
  1503.     if (LowFrequency == LOWEST_FREQUENCY)
  1504.     {
  1505.         rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  1506.     if (rate != AUTO_RATE)
  1507.     {
  1508.  
  1509. /*
  1510.  * Ahah, a beautiful divide by zero handling
  1511.  * if TRAP_TEST defined, just enter 0 into Bins gadget
  1512.  * Unfortunately, ffp math forces a trap on divide by zero, and
  1513.  * this cannot be intercepted without writing assembly code.  Damn.
  1514.  */
  1515.  
  1516. /* #define TRAP_TEST */
  1517.  
  1518. #ifdef TRAP_TEST
  1519.         if (bins_used != DONT_KNOW)  /* May divide by 0 */
  1520. #else
  1521.         if (bins_used != DONT_KNOW && bins_used > 0) /* Safe */
  1522. #endif
  1523.  
  1524.         {
  1525.         double low_f = rate / (2.0 * bins_used * Interleave);
  1526.         sprintf (buffer, "%g", low_f);
  1527.         reset = TRUE;
  1528.         }
  1529.     }
  1530.     if (!reset)
  1531.     {
  1532.         buffer[0] = '\0';
  1533.     }
  1534.     refresh_gadget (low_f_gadgetp, dialog_window_p);
  1535.     }
  1536. }
  1537.  
  1538. static void bins_gadget__update (BOOLEAN force_update)
  1539. {
  1540.     struct StringInfo *string_infop;
  1541.     char *buffer;
  1542.  
  1543.     if (NumberBins == MAX_BINS || force_update)
  1544.     {
  1545.     string_infop = bins_gadgetp->SpecialInfo;
  1546.     buffer = string_infop->Buffer;
  1547.     bins_string__set (buffer);
  1548.     refresh_gadget (bins_gadgetp, dialog_window_p);
  1549.     }
  1550.     low_f_gadget__update ();
  1551. }
  1552.  
  1553. static void bins_string__set (char *buffer)
  1554. {
  1555.     BOOLEAN done = FALSE;
  1556.  
  1557.     if (NumberBins != MAX_BINS)
  1558.     {
  1559.     bins_used = NumberBins;
  1560.     sprintf (buffer, "%ld", NumberBins);
  1561.     done = TRUE;
  1562.     }
  1563.     else if (ReadPtr != NULL && ReadPtr != stdin)
  1564.     {
  1565.         BOOLEAN save_quiet = Quiet;
  1566.     Quiet = TRUE;
  1567.  
  1568.     bins_used = DONT_KNOW;
  1569.     CATCH_ERROR;
  1570.     bins_used = do_ok (FALSE);
  1571.     sprintf (buffer, "%ld", bins_used);
  1572.     done = TRUE;
  1573.     END_CATCH_ERROR;
  1574.  
  1575.     Quiet = save_quiet;
  1576.     }
  1577.     if (!done) buffer[0] = '\0';
  1578. }
  1579.  
  1580.  
  1581. static void message__set (int message_number)
  1582. {
  1583.     static int remember_message = SELECT_PARAMETERS;
  1584.  
  1585.     switch (message_number)
  1586.     {
  1587.     case SELECT_READ_FILE:
  1588.     message_gadget__write (message_gadgetp,
  1589.                    Please_Select_Read_File_S,
  1590.                    dialog_window_p);
  1591.     ActivateGadget (read_file_gadgetp, dialog_window_p, NULL);
  1592.     remember_message = SELECT_READ_FILE;
  1593.  
  1594. #ifdef DISABLE_OK_WHEN_NOT_READY
  1595.     gadget__disable (ok_gadgetp, dialog_window_p);
  1596. #endif
  1597.     break;
  1598.  
  1599.     case SELECT_PARAMETERS:
  1600.  
  1601. #ifdef DISABLE_OK_WHEN_NOT_READY
  1602.     gadget__enable (ok_gadgetp, dialog_window_p);
  1603. #endif
  1604.  
  1605.     message_gadget__write (message_gadgetp,
  1606.                    Set_Parameters_Then_Ok_S,
  1607.                    dialog_window_p);
  1608.     remember_message = SELECT_PARAMETERS;
  1609.     break;
  1610.     case PERFORMING_FFT:
  1611.     message_gadget__write (message_gadgetp,
  1612.                    Attempting_to_Perform_FFT_S,
  1613.                    dialog_window_p);
  1614.     break;
  1615.     case SET_RATE:
  1616.     message_gadget__write (message_gadgetp,
  1617.                    Set_Sampling_Rate_S,
  1618.                    dialog_window_p);
  1619.     remember_message = SET_RATE;
  1620.     ActivateGadget (rate_gadgetp, dialog_window_p, NULL);
  1621.  
  1622. #ifdef DISABLE_OK_WHEN_NOT_READY
  1623.     gadget__disable (ok_gadgetp, dialog_window_p);
  1624. #endif
  1625.  
  1626.     break;
  1627.  
  1628.     case VERIFY_RATE:
  1629.     message_gadget__write (message_gadgetp,
  1630.                    Verify_Sampling_Rate_S,
  1631.                    dialog_window_p);
  1632.     ActivateGadget (rate_gadgetp, dialog_window_p, NULL);
  1633.     remember_message = VERIFY_RATE;
  1634.     break;
  1635.     case REMEMBER_MESSAGE:
  1636.     message__set (remember_message);
  1637.     break;
  1638.     }
  1639. }
  1640.  
  1641. static void do_help (struct Gadget *gadgetp)
  1642. {
  1643.     if (gadgetp->UserData)
  1644.     {
  1645.     help_message ( (char *) gadgetp->UserData);
  1646.     }
  1647.     else
  1648.     {
  1649.     error_message (HELP_MESSAGE_UNAVAILABLE);
  1650.     }
  1651. }
  1652.  
  1653. static char *wb_set_append (char *arguments)
  1654. {
  1655.     wb_append_on = TRUE;
  1656.     name_string_gadget__apply (write_file_gadgetp, set_append);
  1657.     return arguments;
  1658. }
  1659.  
  1660. static char *wb_no_set_append (char *arguments)
  1661. {
  1662.     wb_append_on = FALSE;
  1663.     if (last_address != (APTR) spectrum_select_gadgetp)
  1664.     {
  1665.     string_gadget__reset (write_file_gadgetp, NullString,
  1666.                   dialog_window_p);
  1667.     }
  1668.     name_string_gadget__apply (write_file_gadgetp, set_write);
  1669.     return arguments;
  1670. }
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678. /*
  1679.  * Obsolete Gadgets (not enough room; deemed less important)
  1680.  */
  1681. #if FALSE
  1682.     char ileave_string[20];
  1683.  
  1684.     no_interleave_gadgetp = radio_button__new ("NO", 73, 3);
  1685.     if (Interleave > 1 && Interleave != INVALID_INTERLEAVE)
  1686.     {
  1687.         sprintf (ileave_string, "%ld", Interleave);
  1688.     }
  1689.     else
  1690.     {
  1691.         ileave_string[0] = '\0';
  1692.         if (Interleave != INVALID_INTERLEAVE)
  1693.         {
  1694.         radio_button__in (no_interleave_gadgetp, dialog_window_p);
  1695.         }
  1696.     }
  1697.     interleave_gadgetp = string_gadget__new ("Interleave:", 
  1698.                          ileave_string,
  1699.                          12, 20, 51, 3);
  1700.  
  1701.             else if (address == (APTR) no_interleave_gadgetp)
  1702.             {
  1703.                 struct StringInfo *string_infop = 
  1704.                   interleave_gadgetp->SpecialInfo;
  1705.                 char *buffer = string_infop->Buffer;
  1706.                 buffer[0] = '\0';
  1707.                 refresh_gadget (interleave_gadgetp,
  1708.                         dialog_window_p);
  1709.                 radio_button__in (no_interleave_gadgetp, 
  1710.                           dialog_window_p);
  1711.                 set_no_interleave (NullString);
  1712.                 bins_gadget__update (FALSE);
  1713.             }
  1714.             else if (address == (APTR) interleave_gadgetp)
  1715.             {
  1716.                 CATCH_ERROR
  1717.                 {
  1718.                 string_gadget__apply (interleave_gadgetp,
  1719.                               set_interleave);
  1720.                 }
  1721.                 END_CATCH_ERROR;
  1722.                 radio_button__out (no_interleave_gadgetp,
  1723.                            dialog_window_p);
  1724.                 bins_gadget__update (FALSE);
  1725.             }
  1726.  
  1727. #endif /* obsolete section */
  1728.  
  1729.  
  1730. #endif  /* ifdef AMIGA */
  1731.  
  1732.